package featuremodel.predication;

import featuremodel.FeatureGroup;
import featuremodel.FeatureRep;

import skyblue.Method;
import skyblue.SkyBlueDef;
import skyblue.Variable;

public class CompositeSingleTrue extends Method {

	private Variable feature;
	private FeatureGroup featureGroup;

	public CompositeSingleTrue(Variable feature, FeatureGroup featureGroup) {
		this.feature = feature;
		this.featureGroup = featureGroup;
		getOutputs().addAll(featureGroup.getVariables());

	}

	public void setTobeMethodType() {

		for (int i = 0; i < featureGroup.getVariables().size(); i++) {
			featureGroup.getVariables().get(i).setTobemethodtype(
					SkyBlueDef.METHOD_TYPE_UNBIND);
		}
		feature.setTobemethodtype(SkyBlueDef.METHOD_TYPE_BIND);
	}

	public void clearTobeMethodType() {
		for (int i = 0; i < featureGroup.getVariables().size(); i++) {
			featureGroup.getVariables().get(i).setTobemethodtype(null);
		}
	}

	public void setTobeMethodType2() {

		for (int i = 0; i < featureGroup.getVariables().size(); i++) {
			featureGroup.getVariables().get(i).setTobeMethodType2(
					SkyBlueDef.METHOD_TYPE_UNBIND);
		}
		feature.setTobeMethodType2(SkyBlueDef.METHOD_TYPE_BIND);

	}

	public void clearTobeMethodType2() {
		for (int i = 0; i < featureGroup.getVariables().size(); i++) {
			featureGroup.getVariables().get(i).setTobeMethodType2(null);

		}
	}

	public void execute() {

		FeatureRep fp;
		Variable temp;
		for (int i = 0; i < featureGroup.getVariables().size(); i++) {
			temp = featureGroup.getVariables().get(i);
			fp = (FeatureRep) temp.getValue().getValuerep();
			fp.setBindState(SkyBlueDef.VARIABLE_UNBIND);
			temp.setMethodtype(SkyBlueDef.METHOD_TYPE_UNBIND);
			temp.setTobemethodtype(null);
		}

		fp = (FeatureRep) feature.getValue().getValuerep();
		fp.setBindState(SkyBlueDef.VARIABLE_BIND);
		feature.setMethodtype(SkyBlueDef.METHOD_TYPE_BIND);
		feature.setTobemethodtype(null);

	}

}
